package khiem.gwt.demo.gadgetDesktop.client.view;

import khiem.gwt.demo.gadgetDesktop.client.model.Gadget;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class GadgetContainerView extends SimplePanel {
	private Gadget child;
	private HorizontalPanel titleBar = new HorizontalPanel();
	private VerticalPanel mainLayout = new VerticalPanel();
	private Label title = new Label();
	private Hyperlink edit = new Hyperlink("edit", "");
	private Button minimizeButton = new Button("M");
	private Button closeButton = new Button("C");
	private Button refreshButton = new Button("R");
	private FlexTable editPanel = new FlexTable();
	private boolean open = true;
	private boolean editopen = false;
	
	public GadgetContainerView(Gadget c) {
		child = c;
		buildTitleBar();
		buildMainLayout();
		mainLayout.setWidth("100%");
		setWidget(mainLayout);
		child.refresh();
	}
	
	protected void buildTitleBar() {
		titleBar.add(minimizeButton);
		titleBar.add(title);
		titleBar.add(refreshButton);
		if (child.getGadgetClass().getUserPrefsCount() > 0) {
			titleBar.add(edit);
		}
		titleBar.add(closeButton);
		titleBar.setCellWidth(title, "100%");
		title.setWidth("100%");
		title.setText(child.getTitle());
		buildClickListeners();
	}
	
	private void buildClickListeners() {
		// TODO Auto-generated method stub
		
	}

	protected void buildMainLayout() {
		titleBar.setWidth("100%");
		mainLayout.add(titleBar);
		
		if (child.getGadgetClass().getUserPrefsCount() > 0) {
			mainLayout.add(editPanel);
			editPanel.setWidth("100%");
			buildEditPanel();
		}
		mainLayout.add(child);
	}

	private void buildEditPanel() {
		
		
	}
	

	

}
